﻿
@{
    Layout = "~/Views/Shared/_Edit.cshtml";
}
@model DTO.DTO.Sys.Role.RoleDetailDTO
<form class="layui-form" action="" style="margin-top:20px;">
    <input type="hidden" name="Id" value="@Model.Id" />
    <div class="layui-form-item">
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-inline">
            <input type="text" name="Name" lay-verify="required" autocomplete="off" placeholder="角色名称" class="layui-input" value="@Model.Name">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-inline">
            <input type="checkbox" @(Model.Status == 0 ? "checked=''" : "") name="Status" lay-skin="switch" lay-filter="switchTest" lay-text="正常|禁用">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
@section script{
    <script>
        layui.use("form", function () {
            var form = layui.form
                , layer = layui.layer
                , $ = layui.$;

            var index = parent.layer.getFrameIndex(window.name);

            //监听提交
            form.on('submit(submit)', function (data) {
                var formData = data.field;
                formData.Status = formData.Status === "on" ? 0 : 1;
                $.post("Save", formData, function (d) {
                    if (d.code === 0) {
                        layer.msg(d.msg, { icon: 1 });
                        setTimeout(function () {
                            parent.layer.close(index);
                        }, 1000);
                    }
                    else {
                        layer.msg(d.msg, { icon: 2 });
                    }
                })
                return false;
            });
        });
    </script>
}

